import 'package:flutter/material.dart';
import 'package:labcloud_app/model/user/user_address_model.dart';
import 'package:labcloud_app/model/user/user_wallet_model.dart';
import 'package:provider/provider.dart';
import 'package:graphql_flutter/graphql_flutter.dart';
import 'model/order_model.dart';
import 'model/product/product_ad_model.dart';
import 'model/product/product_model.dart';
import 'model/websocket_model.dart';
import 'route/app_routes.dart';
import 'model/user/user_model.dart';
import 'model/user/user_cart_model.dart';
import 'api/graphql_config.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  // 初始化GraphQL客户端
  final client = GraphQLConfig.initClient();

  runApp(
    MultiProvider(
      providers: [
        ChangeNotifierProvider(create: (context) => UserModel()),
        ChangeNotifierProvider(create: (context) => UserCartModel()),
        ChangeNotifierProvider(create: (context) => UserAddressModel()),
        ChangeNotifierProvider(create: (context) => ProductModel()),
        ChangeNotifierProvider(create: (context) => ProductAdModel()),
        ChangeNotifierProvider(create: (context) => UserWalletModel()),
        ChangeNotifierProvider(create: (context) => OrderModel()),
        ChangeNotifierProvider(create: (context) => WebSocketModel()),
      ],
      child: GraphQLProvider(
        client: client,
        child: MyApp(),
      ),
    ),
  );
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Lab App',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      initialRoute: AppRoutes.initialRoute,
      routes: AppRoutes.routes,
    );
  }
}